Skip to content

perf: avoid quadratic remote form issue merging#16493

Open
Nic-Polumeyv wants to merge 2 commits into
sveltejs:version-3from
Nic-Polumeyv:form-issue-merge
Open

perf: avoid quadratic remote form issue merging#16493
Nic-Polumeyv wants to merge 2 commits into
sveltejs:version-3from
Nic-Polumeyv:form-issue-merge

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

merge_with_server_issues runs whenever preflight validation produces issues, which with the documented oninput pattern means on every keystroke while a form has issues. Merging costs O(S·C + M·K·log M) for S server issues, C client issues, M merged issues and K form keys. 🤓 This change drops it to O(S + C + K + M·log M). 🤓

N fields with N issues (half server, half client), Node 22 x64, median of repeated runs:

fields before after speedup
400 1.6 ms 0.1 ms 15×
800 7.9 ms 0.3 ms 27×
1600 33.0 ms 0.8 ms 42×
3200 163.8 ms 2.2 ms 76×

Small forms are at parity or slightly faster, since the old code already allocated the key array.

Output is unchanged: identical issue-object ordering to the previous implementation across 10,000 randomized cases covering duplicated form keys, duplicated issue names, names absent from the form, mixed server and client issues and empty collections. The merge semantics negotiated in #14744/#14759 are preserved.


Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 986b3e6:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/986b3e6b76b8a5660b94d4a1a7ac6424865632cc

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16493

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 986b3e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant